package com.example.blog.controller;

import com.example.blog.base.Result;
import com.example.blog.entity.Like;
import com.example.blog.entity.vo.like.LikeDetailInfoVO;
import com.example.blog.service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 点赞模块
 * <p>
 * 点赞表 前端控制器
 * </p>
 *
 * @author wlh
 * @since 2024-01-10
 */
@RestController
@RequestMapping("/blog/like")
public class LikeController {

    @Autowired
    private LikeService likeService;


    /**
     * 点赞文章
     *
     * @param articleId 文章ID
     * @return
     */
    @PostMapping("/add/{articleId}")
    public Result<Void> add(@PathVariable Long articleId) {
        likeService.add(articleId);
        return Result.success();
    }


    /**
     * 取消文章
     *
     * @param articleId 文章ID
     * @return
     */
    @PostMapping("/del/{articleId}")
    public Result<Void> del(@PathVariable Long articleId) {
        likeService.del(articleId);
        return Result.success();
    }

    /**
     * 获取最新的点赞信息。
     *
     * @return Result<List < Like>>
     */
    @GetMapping("/new-like")
    public Result<List<LikeDetailInfoVO>> newLike() {
        // 调用likeService中的newLike方法获取最新的点赞信息，并将其封装在Result对象中返回
        return Result.successData(likeService.newLike());
    }


    /**
     * 未读更新为已读
     * @return
     */
    @PutMapping("/read")
    public Result<Void> read() {
        likeService.read();
        return Result.success();
    }

}
